package com.canxin.controller;
import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import org.jeecgframework.core.common.controller.BaseController;
import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
import org.jeecgframework.core.common.model.json.AjaxJson;
import org.jeecgframework.core.common.model.json.DataGrid;
import org.jeecgframework.core.constant.Globals;
import org.jeecgframework.core.util.StringUtil;
import org.jeecgframework.tag.core.easyui.TagUtil;
import org.jeecgframework.web.system.pojo.base.TSDepart;
import org.jeecgframework.web.system.service.SystemService;
import org.jeecgframework.core.util.MyBeanUtils;

import com.canxin.entity.BinduserEntity;
import com.canxin.entity.NoticeEntity;
import com.canxin.entity.UserFocusEntity;
import com.canxin.service.BinduserServiceI;
import com.canxin.service.ChatMenuServiceI;
import com.canxin.service.NoticeServiceI;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import weixin.guanjia.message.entity.ReceiveText;
import weixin.guanjia.message.service.ReceiveTextServiceI;
import weixin.p3.oauth2.rule.RemoteWeixinMethod;

/**   
 * @Title: Controller
 * @Description: 用于处理聊天页面相关的后台逻辑
 * @author zhangdaihao
 * @date 2017-03-12 14:43:41
 * @version V1.0   
 *
 */
@Scope("prototype")
@Controller
@RequestMapping("/chatMenuController")
public class ChatMenuController extends BaseController {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(ChatMenuController.class);

	@Autowired
	private ChatMenuServiceI chatMenuService;
	@Autowired
	private ReceiveTextServiceI receiveTextService;	
	@Autowired
	private NoticeServiceI noticeService;
	
	@Autowired
	private SystemService systemService;
	private String message;
	
	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	
	@RequestMapping(params="initChatMenu")
	@ResponseBody
	public AjaxJson initChatMenu(HttpServletRequest request) throws IOException {
		AjaxJson j = new AjaxJson();
		List<ReceiveText> receiveTextList = receiveTextService.getAllReceiveText("gh_d1ace5896840");
		List<ReceiveText> receiveUserList = receiveTextService.getAllReceiveText("gh_d1ace5896840");
		for(ReceiveText receiveText:receiveUserList)
		{
			String opendId = receiveText.getFromUserName();
			JSONObject userFocusEntity = chatMenuService.getUserFocusInfo(opendId);
			
			if(userFocusEntity.containsKey("openid"))
			{
				System.out.println(userFocusEntity.toString());
			}
		}
		JSONArray jsonArray =JSONArray.fromObject(receiveTextList);
		//Timestamp ts = new Timestamp(System.currentTimeMillis());
		
		//System.out.println(jsonArray.toString());
		j.setSuccess(true);
		
		JSONObject resultJson = new JSONObject();
		//resultJson.put
		//j.setMsg(userFocusEntity.toString());
		return j;
		
	}
}
